package com.hk.commons.exceptions;

import lombok.Getter;
import org.springframework.lang.Nullable;

import java.lang.reflect.Method;

/**
 * @author Kevin
 */
@Getter
public class RequiredLockException extends RuntimeException {

    private final transient String lockKey;

    private final transient Object target;

    private final transient Method method;

    @Nullable
    private final transient Object[] args;

    public RequiredLockException(String lockKey, Object target, Method method, Object[] args) {
        this(lockKey, target, method, args, "Unable to acquire lock");
    }

    public RequiredLockException(String lockKey, Object target, Method method, Object[] args, String message) {
        super(message);
        this.lockKey = lockKey;
        this.target = target;
        this.method = method;
        this.args = args;
    }

    public RequiredLockException(String lockKey, Object target, Method method, Object[] args,
                                 String message, Throwable cause) {
        super(message, cause);
        this.lockKey = lockKey;
        this.target = target;
        this.method = method;
        this.args = args;
    }
}
